<template>
	<view>
		<view class="cu-card case" :class="isCard?'no-card':''">
			<view class="cu-item shadow">
				<view class="image">
					<image :src="qjhc.value"
					 mode="widthFix"></image>
					<!-- <view class="cu-tag bg-blue">史诗</view> -->
					<!-- <view class="cu-bar bg-shadeBottom"> <text class="text-cut">我已天理为凭，踏入这片荒芜，不再受凡人的枷锁遏制。我已天理为凭，踏入这片荒芜，不再受凡人的枷锁遏制。</text></view> -->
				</view>
			</view>
		</view>
		<view v-if="qjhc.tzgg" class="cu-bar bg-white solid-bottom margin-top">
			<view class="action">
				<text class="cuIcon-title text-blue"></text>{{qjhc.tzgg}}
			</view>
		</view>
		<uni-section v-if="qjhc.ankz" :title="tsxx" type="line">
			<view class="example" style="padding: 10px;">
				<!-- 基础表单校验 -->
				<uni-forms ref="valiForm" :rules="rules" :model="valiFormData" labelWidth="80px">
					<uni-forms-item label="身份证号" required name="zjhm">
						<uni-easyinput type="idcard" v-model="valiFormData.zjhm" placeholder="请输入身份证号" />
					</uni-forms-item>
				</uni-forms>
				<button :loading="loading" :disabled="loading" type="primary" @click="submit('valiForm')">提交</button>
			</view>
		</uni-section>
	</view>
</template>
<script>
	var _this;
	var vk = uni.vk;
	import uniForms from "@/pages_bd/components/uni-forms/uni-forms";
	import uniFormsItem from "@/pages_bd/components/uni-forms-item/uni-forms-item";
	export default {
		components:{uniForms,uniFormsItem},
		data() {
			// 页面数据变量
			return {
				qjhc:{
					ankz:false
				},
				syimg:'http://www.hngsxy.com/projectresources/wxapp/infoQueryImg/dzbmjf.jpg',
				tsxx:'',
				loading: false,
				// 校验规则
				rules: {
					zjhm: {
						rules: [{
							required: true,
							errorMessage: '身份证号错误'
						},{
							minLength: 18,
							maxLength: 18,
							errorMessage: '请输入正确的身份证',
						}]
					}
				},
				valiFormData:{zjhm:""},
				isCard: false,
				// init请求返回的数据
				data:{
					
				},
				// 表单请求数据
				form1:{
					
				},
				scrollTop:0,
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		async onLoad(options = {}) {
			vk = uni.vk;
			_this = this;
			this.options = options;
			this.init(options);
			await this.getxxcjcxglobal()
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady(){
			
		},
		// 监听 - 页面每次1
		onShow() {
			
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {
			
		},
		// 监听 - 点击右上角转发时
		onShareAppMessage(options) {
			
		},
		// 函数
		methods: {
			getxxcjcxglobal(){
				return vk.callFunction({
				  url: 'client/gsxy/globalDataCacheKye/pub/vk-global-data.findById',
				  title:'请求中...',
				  data:{
				    _id:'65a6498e9755e3cdbf6ee1e8'
				  }
				}).then((data) => {
					_this.qjhc = data.info;
				}).catch((err) => {});
			},
			submit(ref) {
				_this.loading = true
					this.$refs[ref].validate().then(res => {
						vk.callFunction({
						  url: 'client/cw/pub/gsxy-wx-dzxs-objapi.getOne',
						  title: '请求中...',
						  data: {
						   zjhm: _this.valiFormData.zjhm
						  },
						  success: (data) => {
							  if(data.info){
								  //成功后
								  try {
								  	vk.setStorageSync('dzxs_key',data.info);
								  } catch (e) {
								  	// error
								  }
							  }else{
								uni.showToast({
									title: `没有此用户`,
									icon:'none'
								})
							    _this.tsxx = '没有此用户'
								_this.loading = false
								  return 
							  }
							  
							   // jfzt == 0 未缴费
							  if(data.info.jfzt == '0'){
								  // dlzt == 1 可以登录
								  if(data.info.dlzt == '1'){
										vk.navigateTo('/pages_bd/gsxgj/wxzfceshi');
								  }else{
										uni.showToast({
											title: `报名时间已经暂停`,
											icon:'none'
										})
									  _this.tsxx = '报名时间已经暂停'
								  }
							  }else{
									uni.showToast({
										title: `已经缴费成功`,
										icon:'none'
									})
								  _this.tsxx = '已经缴费成功'
							  }
								_this.valiFormData.zjhm = '';
								_this.loading = false;
						  }
						});
					}).catch(err => {
						_this.tsxx = err[0].errorMessage;
						//_this.valiFormData.zjhm = '';
						uni.showToast({
							title: err[0].errorMessage,
							icon:'none'
						})
						_this.loading = false;
					})
			},
			IsCard(e) {
				this.isCard = e.detail.value
			},
			// 页面数据初始化函数
			init(options){
				//vk.reLaunch("/pages_template/uni-id/index/index");
			},
			pageTo(path){
				vk.navigateTo(path);
			}
		},
		// 监听器
		watch:{
			
		},
		// 计算属性
		computed:{
			
		}
	}
</script>
<style lang="scss" scoped>
	
	
</style>